const fs = require('fs');
const path = require('path');

function readdirFiles(name, url = './files') {
  fs.readdir(url, (err, files) => {
    if (err) {
      console.error('Error reading directory:', err);
      return;
    }

    files.forEach((file, index) => {
      const oldPath = path.join(url, file);
      const newFileName = `${name}${index + 1}`;
      const newPath = path.join(url, newFileName);

      fs.rename(oldPath, newPath, (err) => {
        if (err) {
          console.error('Error renaming file:', err);
        } else {
          console.log(`Renamed ${file} to ${newFileName}`);
        }
      });
    });
  });
}
readdirFiles('xxxxcxbx')
